package com.salt.modules.sys.app;

import com.salt.common.json.AjaxJson;
import com.salt.core.web.BaseController;
import com.salt.modules.sys.entity.UserAppDevice;
import com.salt.modules.sys.service.UserAppDeviceService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @Description
 * @Author salt
 * @Date 2022/12/31
 * @Version 1.0.1
 */
@RestController
@AllArgsConstructor
@RequestMapping("/app/sys/device")
public class AppUserAppDeviceController extends BaseController {

    private final UserAppDeviceService userAppDeviceService;

    @PostMapping("save")
    public AjaxJson save(@RequestParam("uid") String uid,
                         @RequestParam("aid") String aid,
                         @RequestParam("ext") Integer ext) {
        return userAppDeviceService.saveDevice(uid, aid, ext);
    }

    @GetMapping("find")
    public AjaxJson find(@RequestParam("uid") String uid) {
        UserAppDevice userAppDevice = userAppDeviceService.find(uid);
        if (userAppDevice != null) {
            return AjaxJson.success().put("ext", userAppDevice.getFreeCode());
        }
        return AjaxJson.success().put("ext", null);
    }

}
